﻿#region Imports
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using CommonUtilities.Enums;
using CommonUtilities.Extensions;
#endregion Imports

namespace BulkRenamer.App.WPF.Converters
{
    public class PathValidatorConverter : IValueConverter
    {
        #region Declaration
        /// <summary>
        /// Default font colour
        /// </summary>
        public static SolidColorBrush DefaultFontColour = Brushes.Green;
        #endregion Declaration

        #region IValueConverter Members
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ePathValidation pathValidationType;

            switch ((string)parameter)
            {
                case "F":
                case "File":
                    pathValidationType = ePathValidation.File;
                    break;

                case "D":
                case "Directory":
                    pathValidationType = ePathValidation.Directory;
                    break;

                default:
                    throw new InvalidOperationException("Invalid path validation type");
            }

            if (((string)value).Contains("<") && ((string)value).Contains(">")) return Brushes.Gray;
            else return ((string)value).ValidatePath(pathValidationType) ? DefaultFontColour : Brushes.Red;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
        #endregion IValueConverter Members
    }
}
